package com.cloudfun.msglisten.ws.haier.handler;

import com.alibaba.fastjson.JSONObject;
import com.cloudfun.msglisten.common.constant.RabbitConstants;
import com.cloudfun.msgsubscribe.DeviceInfo;
import com.cloudfun.msgsubscribe.Topic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Created by Huqin on 2020/3/30
 */
@Slf4j
@Component
public class DeviceOnlineEventMsgHandler extends AbstractDeviceMsgHandler {

    @Override
    public boolean canHandle(String topicName) {
        return "online".equals(topicName);
    }

    @Override
    protected void doHandle(JSONObject jsonObject, DeviceInfo deviceInfo, String appId) {
        deviceInfo.setAttr("online", "online");
        // 发往外部
        log.info("2G设备消息：{}发送到外部：{}", deviceInfo, appId);
        externalRabbitTemplate.convertAndSend(RabbitConstants.Exchange.DEVICE_EVENT, appId, deviceInfo);
        // 内部广播
        rabbitTemplate.convertAndSend(RabbitConstants.Exchange.DEVICE_EVENT, "", deviceInfo);
        // ws
//        remoteMessageService.sendMsg(Topic.EVENT, deviceInfo);
    }

}
